﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WeChatParking.Core.BLL
{
    /// <summary>
    /// 首页显示
    /// </summary>
    public class Report
    {
        public decimal GetDailyReport( int enter_id, DateTime dayTime, out int PayCount, out int inCount, out int outCount)
        {
            decimal PayAmount = 0M;
            PayCount = 0;
            inCount = 0;
            outCount = 0;
            string SQLPay = String.Format("SELECT SUM(pay_fee) PayAmount,COUNT(*) PayCount FROM dbo.order_info WHERE pay_time >='{0}'", dayTime);
            string SQLIn = String.Format("SELECT COUNT(*) inCount FROM dbo.CarRecord WHERE inTime >='{0}'", dayTime);
            string SQLOut = String.Format("SELECT COUNT(*) outCount FROM dbo.CarRecord WHERE outTime >='{0}'", dayTime);
            if (enter_id>0)
            {
                SQLPay += String.Format("AND EnterpriseID={0}", enter_id);
                SQLIn += String.Format("AND Enterprise_ID={0}", enter_id);
                SQLOut += String.Format("AND Enterprise_ID={0}", enter_id);
            }
            using (var dbContext = Repository.DbContext.Create())
            {

                var dataPay = dbContext.GetListBySql<Core.BLL.DayPay>(SQLPay, null).ToList();
                var dataIn = dbContext.GetListBySql<int>(SQLIn, null).ToList();
                var dataOut = dbContext.GetListBySql<int>(SQLOut, null).ToList();
                if (dataPay != null && dataPay.Count > 0)
                {
                    PayAmount = dataPay[0].PayAmount;
                    PayCount = dataPay[0].PayCount;
                }
                if (dataIn != null && dataIn.Count > 0)
               
                    inCount = dataIn[0];
                if (dataOut != null && dataOut.Count > 0)
                outCount = dataOut[0];
                
            }
            return PayAmount;
        }
    }
    public class DayPay
    {
        public decimal PayAmount { get; set; }
        public int PayCount { get; set; }
    }
}
